package com.bdi.mqtt_broker.service.impl;

import com.bdi.mqtt_broker.model.InternalMessage;
import com.bdi.mqtt_broker.mqtt_protocol.ProtocolProcess;
import com.bdi.mqtt_broker.service.MessageService;
import io.netty.handler.codec.mqtt.MqttQoS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author WangNing
 * @version 1.0
 * @date 2020/12/10 21:40
 */
@Service
public class MessageServiceImpl implements MessageService {

    @Autowired
    ProtocolProcess protocolProcess;

    @Override
    public void sendMessage(InternalMessage internalMessage) {

        protocolProcess.publish()
                .sendPublishMessage(internalMessage.getTopic(), MqttQoS.valueOf(internalMessage.getMqttQoS()),
                        internalMessage.getMessageBytes(), false, false, null);

        return;

    }
}
